package com.travel.controller;

import com.travel.pojo.City;
import com.travel.service.CityService;
import com.travel.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/city")
public class CityController {

    @Autowired
    private CityService cityService;

    @RequestMapping("/add")
    public Map<String, Object> add(City city) {
        cityService.add(city);
        return JsonResult.getSuccessResult("添加成功", city);
    }

    @RequestMapping("/update")
    public Map<String, Object> update(City city) {
        cityService.update(city);
        return JsonResult.getSuccessResult("修改成功", null);
    }

    @RequestMapping("/delete")
    public Map<String, Object> delete(Integer id) {
        cityService.delete(id);
        return JsonResult.getSuccessResult("删除成功", null);
    }

    @RequestMapping("/list")
    public Map<String, Object> listAll(City city) {
        return JsonResult.getSuccessResult("成功", cityService.getList(city));
    }
}
